<%@ include file="/common/taglibs.jsp" %>

	<script type="text/javascript">	
	$(document).ready(function() {	
		
		$('.edit-paymentrequest-link').click(function() {
			$(this).bind("ajaxSend", function(){

				$(this).after("<img  id='loading' src='<c:url value='/images/ajax-loader.gif'/>' alt='loading' />");

				 }).bind("ajaxComplete", function(){

					$('#loading').remove();

				 });
			
			loadDiv('content', 'showEditPaymentrequest.do?id=' + $(this).attr('paymentrequestId'));
		});		
		$('.process-paymentrequest-link').click(function() {
			$(this).bind("ajaxSend", function(){

				$(this).after("<img  id='loading' src='<c:url value='/images/ajax-loader.gif'/>' alt='loading' />");

				 }).bind("ajaxComplete", function(){

					$('#loading').remove();

				 });
			loadDiv('content', 'processPaymentrequest.do?id=' + $(this).attr('paymentrequestId'));
		});
		// $(".tablesorter").tablesorter();		 
      	$(".tablesorter").tablesorter({ sortInitialOrder: 'desc',sortList:[[3,1]]}).tablesorterPager({container: $("#pager")});               
      	//$(".tablesorter").tablesorter().tablesorterPager({container: $("#pager")});               

	});
		 
	</script>
	<div>
		<c:choose>
  				<c:when test="${empty paymentrequestList}">
  					<div style="margin-top:'100px'; text-align:center; "><spring:message code="paymentrequestlist.table.emptymessage"></spring:message></div>
  				</c:when>
  				<c:otherwise></c:otherwise>
		</c:choose>
  		</div>	
	<%@ include file="/common/pager.jsp" %>	
				<table class="tablesorter">			
				 <c:choose>
					<c:when test="${!empty paymentrequestList}">
						<thead>
						<c:if test="${messgae!='null'}">
									<tr>
									<th align="center" colspan="13"><font size="4"><c:out value="${message}"></c:out></font></th>
									</tr>
								</c:if>							
							<!--tr><th nowrap><input type="checkbox" id="check-all">&#10;<spring:message code="common.select.all"/></th -->
								<c:if test="${isFinanceUser || isAdminUser}">
                                <th><spring:message code="paymentrequestList.table.heading.processPaymentRequest" /></th>
                                </c:if>
								<th><spring:message code="paymentrequest.id"/></th>
								<th><spring:message code="paymentrequestList.table.heading.createdBy"/></th>
								<th><spring:message code="label.creationDate"/></th>
								<th><spring:message code="common.number.days.open"/></th>
								<th><spring:message code="editDonoraward.label.amount"/></th>			
								<th><spring:message code="label.type" /></th>
								<th><spring:message code="paymentrequestList.table.heading.statusCode"/></th>
								<th><spring:message code="paymentrequestList.table.heading.payee"/></th>
								<th><spring:message code="paymentrequestList.table.heading.paymentmethod"/></th>
								<th><spring:message code="paymentrequestList.table.heading.paymentConfirmationNumber"/></th>
								<th><spring:message code="paymentrequestList.table.heading.purposeOfExpenditure"/></th>
							</tr>
						</thead>		
					<tbody id="paymentRqst">
						<c:forEach items="${paymentrequestList}" var="paymentrequest">
							<tr>
							    <!--td><input type="checkbox" name="check_element" value="${paymentrequest.id}"></td-->
                              <c:if test="${isFinanceUser || isAdminUser}">
								<td  width="10%">
                                  <a href="javascript://" class="blue_btn process-paymentrequest-link" paymentrequestId="${paymentrequest.id}" style="font-color:white;"><spring:message code="paymentrequestlist.table.link.process" /></a>
                                </td>
                              </c:if>
								<td>
<%--                                 <c:choose> --%>
<%--                                   <c:when test="${isAdminUser || isGrantUser || isStaffUser ||  isKmUser || isSrManagementUser}"> --%>
<%--                                       <a href="javascript://" class="edit-paymentrequest-link" paymentrequestId="${paymentrequest.id}">${paymentrequest.id}</a> --%>
<%--                                   </c:when> --%>
<%--                                   <c:otherwise> --%>
<%--                                     ${paymentrequest.id}                                                                       --%>
<%--                                   </c:otherwise> --%>
<%--                                 </c:choose> --%>
                                  <a href="javascript://" class="edit-paymentrequest-link" paymentrequestId="${paymentrequest.id}">${paymentrequest.id}</a></td>
                                </td>
								<td>${paymentrequest.createdBy.fullName}</td>
								<td><fmt:formatDate value="${paymentrequest.creationDate}" pattern="MM/dd/yyyy"/></td>
								<td><c:if test="${(paymentrequest.statusCode!='Paid') && (paymentrequest.statusCode!='Cancelled')}">
								   ${paymentrequest.numberOfDays}
								   </c:if>
								</td>
								<!-- <td><a href="javascript://" class="edit-paymentrequest-link" paymentrequestId="${paymentrequest.id}">${paymentrequest.paymentIdentifiedInformation}</a></td> -->
								<td><fmt:formatNumber type="currency" value="${paymentrequest.amount}" pattern="$#,##0.##;"/></td>									
								<td>${paymentrequest.paymenttype.paymenttypename}</td>
								<td>${paymentrequest.statusCode}</td>
								<td>${paymentrequest.payee.payeeName}</td>
								<td>${paymentrequest.paymentmethod}</td>					
								<td>${paymentrequest.invoicenumber}</td>
								<td>${paymentrequest.purposeOfExpenditure}</td>			
							</tr>
						</c:forEach>
						    <!--tr align="center"><td align="left" colspan="12"><input type="button" class="blue_btn" name="view"  value="View Selected Payment Requests" align="center" tabindex="-1"><input type="button" class="blue_btn" name="view" value="Process Payment Request" align="center" tabindex="-1"></td></tr-->
							</c:when>
							<c:otherwise>
							<c:set  var="m" value="${message}"/>
								<c:if test="${! empty m}">
									<thead>
									<tr>
									<th colspan="12"><font size="4"><c:out value="${message}"></c:out></font></th>
									<tr><td colspan="14"> Your query has returned 0 records </td></tr>
									</thead>
								</c:if>	
							<c:if test="${ !empty param.action}">					  
								   <tr><td colspan="12"> Your query has returned 0 records </td></tr>
								 </c:if>  
							</c:otherwise>
				</c:choose>	
			
					</tbody>
				</table>